Skip to content

Change private local inference to allow inferring private local for private vals constructor parameters #23378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KacperFKorban
Copy link
Member

closes #22620

@KacperFKorban
Copy link
Member Author

It looks like this change breaks a pattern that used to work before e.g.:

sealed abstract class Tree[+A](
  final val key: A
)
final class RedTree[+A](key: A) extends Tree[A](key)
object RedTree {
  def unapply[A](t: RedTree[A]) = Some((t.key))
}

Since we prefer choosing private members when there are multiple denotations, then this example breaks, since:

  1. Parameter key from RedTree is private local at first
  2. We try accessing it from the companion object and make it non local as a consequence
  3. It becomes private, so it clashes with the inherited final val key

The decision was to also allow for class parameters to be inferred as private local, but looks like it might be a trade-off.

Note: I tried changing the compiler, so that the non-private denotation is preferred, but that broke too many things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

private[this] inference does not work for constructor parameters
1 participant